package com.yicong.ants.ui.order;

import android.os.Bundle;
import android.util.Pair;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.cchao.simplelib.core.RxHelper;
import com.cchao.simplelib.ui.activity.BaseTitleBarActivity;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.databinding.OrderHistoryTabActivityBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * 购买历史 （二次消费，特惠景区）
 *
 * @author cchao
 * @version 2019-08-23.
 */
public class BillHistoryTabActivity extends BaseTitleBarActivity<OrderHistoryTabActivityBinding> {
    List<Pair<String, Fragment>> mContent;
    int defaultSelect = 0;

    @Override
    protected int getLayout() {
        return R.layout.order_history_tab_activity;
    }

    @Override
    protected void initEventAndData() {
        setTitleText("购买记录");
        defaultSelect = getIntent().getIntExtra(Constants.Extra.Index, 0);
        mContent = new ArrayList<>();
        mContent.add(Pair.create("景区门票", getFragments(Constants.Extra.Portal)));
        mContent.add(Pair.create("二次消费项", getFragments(Constants.Extra.Project)));
//        mContent.add(Pair.create("特价票", getFragments("3")));
        initViewPager();
        RxHelper.timerConsumer(300, aLong -> {
            //
            mDataBind.viewPage.setCurrentItem(defaultSelect);
        });
    }

    public Fragment getFragments(String category) {
        Fragment fragment = new TicketOrderListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Constants.Extra.Category, category);
        fragment.setArguments(bundle);
        return fragment;
    }

    private void initViewPager() {
        mDataBind.viewPage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return mContent.get(i).second;
            }

            @Override
            public int getCount() {
                return mContent.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return mContent.get(position).first;
            }
        });
        mDataBind.tabLayout.setViewPager(mDataBind.viewPage);
        mDataBind.viewPage.setOffscreenPageLimit(mContent.size());
        mDataBind.tabLayout.onPageSelected(0);
    }

    @Override
    protected void onLoadData() {

    }
}
